package fy.mdm.operator;

import java.util.ArrayList;
import java.util.List;

import com.seeyon.v3x.services.flow.bean.FlowExport;
import com.seeyon.v3x.services.form.bean.ValueExport;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.operate.IFormOperator;
import fy.mdm.bean.NewFindeBean;
import fy.mdm.dao.NewFindeDao;

public class NewFindeOperator extends AForm_Save_Operator implements
		IFormOperator {
	private NewFindeBean newfind = new NewFindeBean();
	private List<String> PlanNumberList = new ArrayList<String>();
	private List<String> TakingNumber = new ArrayList<String>();
	private List<String> FactoryId = new ArrayList<String>();
	private List<String> line_Number = new ArrayList<String>();
	private List<String> factory = new ArrayList<String>();
	private List<String> product_Name = new ArrayList<String>();
	private List<String> plan_Date = new ArrayList<String>();
	private List<String> part_number = new ArrayList<String>();
	private List<String> box_Identifier = new ArrayList<String>();
	private List<String> buckle_number = new ArrayList<String>();
	private List<String> limit = new ArrayList<String>();
	private List<String> ceiling = new ArrayList<String>();
	private List<String> procurement = new ArrayList<String>();
	private List<String> pieces_number = new ArrayList<String>();

	public String getFormName() {
		return "销售订单审批";
	}

	@Override
	protected void parseOtherField_FirstStep(FlowExport flowExport) {
		newfind.setSummaryId(super.formBean.getSummaryId());
		newfind.setBillname(flowExport.getFlowTitle());
		newfind.setApplier(flowExport.getFlowCreatePerson().getName());
		newfind.setTs(flowExport.getFlowCreateTime());

	}

	protected void parseValueExport(ValueExport ve) {

		String fieldName = ve.getDisplayName();
		if ("计划单号".equals(fieldName)) {
			newfind.setPlan_id(ve.getValue());
			// System.out.println(ve.getValue());
		} else if ("本厂编号".equals(fieldName)) {
			this.FactoryId.add(ve.getValue());
			// System.out.println(FactoryId);
		} else if ("计划单数量".equals(fieldName)) {
			this.PlanNumberList.add(ve.getValue());
		} else if ("要货数量".equals(fieldName)) {
			this.TakingNumber.add(ve.getValue());
		} else if ("行号".equals(fieldName)) {
			this.line_Number.add(ve.getValue());
		} else if ("工厂".equals(fieldName)) {
			this.factory.add(ve.getValue());
		} else if ("产品名称".equals(fieldName)) {
			this.product_Name.add(ve.getValue());
		} else if ("计划日期".equals(fieldName)) {
			this.plan_Date.add(ve.getValue());
		} else if ("零件号".equals(fieldName)) {
			this.part_number.add(ve.getValue());
		} else if ("混箱标识".equals(fieldName)) {
			this.box_Identifier.add(ve.getValue());
		} else if ("成品扣库数量".equals(fieldName)) {
			this.buckle_number.add(ve.getValue());
		} else if ("行_允差下限".equals(fieldName)) {
			this.limit.add(ve.getValue());
		} else if ("行_允差上限".equals(fieldName)) {
			this.ceiling.add(ve.getValue());
		} else if ("是否采购".equals(fieldName)) {
			this.procurement.add(ve.getValue());
		} else if ("每箱片数".equals(fieldName)) {
			this.pieces_number.add(ve.getValue());
		}

	}

	protected boolean save() {
		newfind.setFactory_id(FactoryId);
		newfind.setPlan_number(PlanNumberList);
		newfind.setTaking_number(TakingNumber);
		newfind.setLine_Number(line_Number);
		newfind.setFactory(factory);
		newfind.setProduct_Name(product_Name);
		newfind.setPlan_Date(plan_Date);
		newfind.setPart_number(part_number);
		newfind.setBox_Identifier(box_Identifier);
		newfind.setBuckle_number(buckle_number);
		newfind.setLimit(limit);
		newfind.setCeiling(ceiling);
		newfind.setProcurement(procurement);
		newfind.setPieces_number(pieces_number);
		NewFindeDao dao = new NewFindeDao();
		dao.setNewfind(newfind);
		try {
			return dao.NewFindeChange();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			newfind = null;
		}
		return success;
	}

}
